package com.czp.discount;

import com.czp.discount.domain.UserInfo;
import com.czp.discount.repository.UserInfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@SpringBootApplication
public class DiscountApplication {
	@Autowired
	private UserInfoRepository userInfoRepository;

	public static void main(String[] args) {
		SpringApplication.run(DiscountApplication.class, args);
	}

	@RequestMapping("/index")
	public String index(){
		return "/index";
	}

	@Modifying
	@RequestMapping("adduser")
	public String addUser(){
		UserInfo userInfo = new UserInfo();
		userInfo.setName("chen");
		userInfo.setRole("cmd");
		userInfo.setPassword("123456");
		userInfoRepository.save(userInfo);
		return "HAHA";
	}

	@RequestMapping("getuser")
	public String getUser(){
		List<UserInfo> userInfo = userInfoRepository.findUserInfoByRole("cmd");
		UserInfo us = userInfo.get(0);
		return us.getName();
	}


}
